#
# Script1.ps1
#

function Create-Object($Schema,$Table,$Comment)
{
	#Build a hash table with the properties
	$properties=[ordered]@{Schema=$Schema
						Table=$Table
						Comment=$Comment
	}

	#Start by creating an object of type PSObject
	$object=New-Object -TypeName PSObject -Property $properties

	return $object
}


$myObject=Create-Object -Schema "MySchema" -Table "MyTable" -Comment "MyComment"
$myObject

"My Schema=$($myObject.Schema)"

$myObject.Schema="New Schema"
$myObject.Comment="New Comment"
$myObject

function Create-Object($Schema,$Table,$Comment)
{
	$object=New-Object -TypeName psobject

	Add-Member -InputObject $object `
				-MemberType NoteProperty
				-Name Schema
				-Value $Schema

	$object | Add-Member -MemberType NoteProperty
						-Name Table
						-Value $Table

	$object | Add-Member -MemberType NoteProperty
						-Name Comment
						-Value $Comment

	return $object
}

$myObject=Create-Object -Schema "MySchema" -Table "MyTable" -Comment "MyComment"
$myObject

"My Schema=$($myObject.Schema)"
$myObject.Schema="New Schema"
$myObject.Comment="New Comment"
$myObject

#add alias for one of the properties
Add-Member -InputObject $myObject
			-MemberType AliasProperty
			-Name "Description"
			-Value "Comment"
			-PassThru

"Comment......:$($myObject.Comment)"
"Descripton...:$($myObject.Description)"

#add script block to object
$block={
	$fqn=$this.Schema+'.'+$this.Table
	return $fqn
}

Add-Member -InputObject $myObject
			-MemberType ScriptMethod
			-Name 'FullyQualifiedName'
			-Value $block
			-PassThru

$myObject.FullyQualifiedName()

#script block with parameters
$block={
	param($DatabaseName)
	$dqn="$DatabaseName.$($this.Schema).$($this.Table)"
	return $dqn
}

Add-Member -InputObject $myObject
			-MemberType ScriptMethod
			-Name "DatabaseQualifiedName"
			-Value $block
			-PassThru

$myObject.DatabaseQualifiedName("MyDBName")


